package com.example.hyw.szysteam.view;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;

import com.example.hyw.szysteam.POJO.UserInfo;
import com.example.hyw.szysteam.R;
import com.qmuiteam.qmui.widget.QMUITopBar;

import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

/**
 * Created by HYW on 2018/5/22.
 */

public class MineFragment extends Fragment implements View.OnClickListener{
    LinearLayout buttonMineInfo;
    LinearLayout buttonTest;
    LinearLayout buttonMistakeBook;
    LinearLayout buttonHonor;
    LinearLayout buttonSetting;
    TextView infoUsername;
    TextView infoSchool;
    View view;
    private QMUITopBar mTopBar;
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view=inflater.inflate(R.layout.fragment_mine,container,false);
        initTopBar();
        initView();
        return view;
    }
    private void initTopBar(){
        mTopBar=view.findViewById(R.id.mine_topbar);
        mTopBar.setTitle("我").setTextColor(getResources().getColor(R.color.myWhite));
    }
    private void initView(){
        buttonMineInfo=view.findViewById(R.id.button_info);
        buttonTest=view.findViewById(R.id.button_test);
        buttonMistakeBook=view.findViewById(R.id.mistake_book);
        buttonHonor=view.findViewById(R.id.button_honor);
        buttonSetting=view.findViewById(R.id.button_setting);
        infoUsername=view.findViewById(R.id.info_username);
        infoSchool=view.findViewById(R.id.info_school);
        buttonMineInfo.setOnClickListener(this);
        buttonTest.setOnClickListener(this);
        buttonMistakeBook.setOnClickListener(this);
        buttonHonor.setOnClickListener(this);
        buttonSetting.setOnClickListener(this);
        if(UserInfo.getName()!=null){
            infoUsername.setText(UserInfo.getName());
        }
        if(UserInfo.getSchool()!=null){
            infoSchool.setText(UserInfo.getSchool());
        }
    }

    @Override
    public void onClick(View view){
        Intent intent;
        switch (view.getId()){
            case R.id.button_info:
                intent=new Intent(getActivity(),UserInfoActivity.class);
                startActivity(intent);
                break;
            case R.id.button_test:
                intent=new Intent(getActivity(),TestActivity.class);
                startActivity(intent);
                break;
            case R.id.mistake_book:
                intent=new Intent(getActivity(),MistakeBookActivity.class);
                startActivity(intent);
                break;
            case R.id.button_honor:
                intent=new Intent(getActivity(),HonorActivity.class);
                startActivity(intent);
                break;
            case R.id.button_setting:
            default:
                intent=new Intent(getActivity(),SettingActivity.class);
                startActivity(intent);
        }
    }
}
